package com.guoyh.adapter.base

import androidx.databinding.ViewDataBinding

/**
 * @auther      guoyh
 * @Date  6/24/21 2:29 PM
 * @Describe   单选的Adapter
 */
abstract class BaseRlvBindSingleSelAdapter<T, DB : ViewDataBinding>(
    layoutResId: Int,
    data: MutableList<T>,
    //默认选中的下标
    defaultSelPost: Int = -1
) :
    BaseRlvBindAdapter<T, DB>(layoutResId, data) {

    /**
     * 选中的下标
     */
    var selPosition = -1

    /**
     * 上次选中的下标
     */
    private var lastSelPos = -1;

    init {
        selPosition = defaultSelPost
        lastSelPos = selPosition
    }


    /**
     * 选中
     */
    fun setSelPos(selPos: Int) {
        this.selPosition = selPos
        notifyItemChanged(selPos)
        notifyItemChanged(lastSelPos)
        lastSelPos = selPos
    }

    /**
     * 是否选中
     */
    fun isSelect(currLayoutPos: Int) = selPosition == currLayoutPos

    /**
     * 获取选中的 Item
     */
    fun getSelPosItem(): T {

        return data[selPosition]
    }


}